﻿//checkbox select all or cancel all
function checkAll(flag,name){
	var cbs=document.getElementsByName(name);
	if(cbs.length){		
		for (var i = 0; i < cbs.length; i++) { 
			if(!cbs[i].disabled){
				cbs[i].checked = flag;
			}
				       
	    }  
	}else{
		if(!cbs.disabled){
			cbs.checked = flag; 
		}
	}
}
//test checkbox select all or cancel all have check
function ifCheck(name){
	var r=false;
	var cbs=document.getElementsByName(name);
	if(cbs.length){		
		for (var i = 0; i < cbs.length; i++) {   
	       if(cbs[i].checked){
	    	   r=true;
	    	   break;
	       }       
	    }  
	}else{
		 r=cbs.checked;   
	}
	return r;
}
//获取多选框数据
function getCheckValues(name){
	var t= new Array();
	var cbs=document.getElementsByName(name);
	if(cbs.length){		
		for (var i = 0; i < cbs.length; i++) {   
	       if(cbs[i].checked){
	    	   t[t.length]=cbs[i].value;
	       }       
	    }  
	}else{
		if(cbs.checked){
			t[t.length]=cbs.value;
		} 
	}
	return t;
}
//long->yyyy-MM-dd HH:mm:ss
function formatDate(time){
	var date=new Date(time);
	var m = date.getMonth()+1;
	var d = date.getDate();
	var H=date.getHours();
	var n=date.getMinutes();
	var s=date.getSeconds();
	return date.getFullYear()+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d)+" "+(H<10?('0'+H):H)+":"+(n<10?('0'+n):n)+":"+(s<10?('0'+s):s);
}

//long->yyyy-MM-dd
function formatShotDate(time){
	var date=new Date(time);
	var m = date.getMonth()+1;
	var d = date.getDate();
	return date.getFullYear()+"-"+(m<10?('0'+m):m)+"-"+(d<10?('0'+d):d);
}

//获取分类多选的checkbox Html字符串
function createTypeCb(objs,colNum,name,defaultType){
	var s="";
	for(var i=0;i<objs.length;i+=colNum){		
		for(var j=0;j<colNum;j++){
			if((i+j)<objs.length){
				var o=objs[i+j];
				var c=(defaultType&&defaultType.indexOf(o.code)!=-1)?"checked='checked'":"";
				s+="<input type='checkbox' name='"+name+"' value='"+o.code+"' "+c+"/>"+o.name+"&nbsp;&nbsp;&nbsp;";
			}			
		}
		s+="<br/>";
	}
	return s;
}

//获取分类多选的radio Html字符串
function createTypeRd(objs,colNum,name,defaultType){
	var s="";
	for(var i=0;i<objs.length;i+=colNum){		
		for(var j=0;j<colNum;j++){
			if((i+j)<objs.length){
				var o=objs[i+j];
				var c="";
				if(defaultType==''){
					c=(i+j)==0?"checked='checked'":"";
				}else{
					c=defaultType==o.code?"checked='checked'":"";
				}
				s+="<input type='radio' name='"+name+"' value='"+o.code+"' "+c+" onclick='doQuery();'/>"+o.name+"&nbsp;&nbsp;&nbsp;";
			}			
		}
		s+="<br/>";
	}
	return s;
}

//分解类型为中文显示
function splitType(types,type){
	var t=type.split("-");
	var s='';
	for(var j=0;j<t.length;j++){
		for(var i=0;i<types.length;i++){
			if(types[i].code==t[j]){
				s+=types[i].name+" ";
				break;
			}
		}
	}
	return s;
}

//直接获取资源
function getResouce(souType,path){
	location.href="resource!getResourceDirect.action?souType="+souType+"&souPath="+path;
}

// 打开普通窗口 并返回句柄 
function openWin(url, width, height, name, top, left, params) {
	var name = (typeof(name) != 'undefined') ? name : "";
	var top = (typeof(top) != 'undefined') ? top : (window.screen.availHeight - height) / 2;
	var left = (typeof(left) != 'undefined') ? left : (window.screen.availWidth - width) / 2;
	var params = (typeof(params) != 'undefined') ? params : "toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=yes";
	
	return window.open(url, name, "width=" + width + ", height=" + height + ", top=" + top + ", left=" + left + "," + params);
}

//软件资源常量
var SOU_TYPE=[{key:'TYPE_SOFT',name:'安卓软件'},{key:'TYPE_MUSIC',name:'音乐'},{key:'TYPE_MOVIE',name:'视频'},{key:'TYPE_PIC',name:'图片'},{key:'TYPE_BOOK',name:'电子书'},{key:'TYPE_PHONE_BAK',name:'手机备份'}];


//获取常量显示值
function getConst(sou,key){
	var r='';
	for(var n in sou){
		if(sou[n].key==key){
			r=sou[n].name;
			break;
		}
	}
	return r;
}
//填充选择栏
function fillConstSel(sou,id){
	var select=$("#"+id);
	for(var n in sou){		
		select.append("<option value='"+sou[n].key+"'>"+sou[n].name+"</option>");		
	}
}
//重置方法
function resetEx(form){
	form.reset();
	if($('#q_beginTime')){
		$('#q_beginTime').datebox('setValue','');
	}
	if($('#q_endTime')){
		$('#q_endTime').datebox('setValue','');	
	}
}
//设置select默认值
function setSelect(id, val) {        
    var s =document.getElementById(id); 
    for (var i = 0; i < s.options.length; i++) {        
        if (s.options[i].value == val) {        
        	s.options[i].selected = true;        
        	break;        
        }        
    }
} 
//给td设置style
function setTdStyle(row){
	for(var i=0;i<row.children.length;i++){
		var td=row.children[i];
		if(td.innerHTML==''){
			td.innerHTML='&nbsp;';
		}
		td.className="STYLE2";		
	}
}

//地区填充选择栏
function fillSelectArea(bUrl,id,selVal){	
	var url=bUrl+"/area!getSelectArea.action";
	$.post(url, '' ,function callback(txt){  
			var select=$("#"+id);
			txt=txt.substr(1,txt.length-2).replace(new RegExp("\"","g"),"");
			var t=txt.split(",");	
			for(var i=0;i<t.length;i++){
				var item=t[i].split(":");
				select.append("<option value='"+item[0]+"'>"+item[1]+"</option>");
			}	
			if(selVal){			
				$("#"+id+" option[value='"+selVal+"']").attr("selected","true");
			}
		}	
	);	
}
